package com.example.calculadora;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class CalculadoraActivity extends Activity {

	double num1; //primeiro numero
	double num2;
	double res;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_calculadora);

		final EditText ediNum1 = (EditText) findViewById(R.id.edi_num1);
		final EditText ediNum2 = (EditText) findViewById(R.id.edi_num2);
		final TextView resultado = (TextView) findViewById(R.id.edi_resultado);

		final Button btSomar = (Button) findViewById(R.id.btAdicao);
		final Button btSubtrair = (Button) findViewById(R.id.btSubtracao);
		final Button btDividir = (Button) findViewById(R.id.btDivisao);
		final Button btMultiplicar = (Button) findViewById(R.id.btMultiplicar);
		final Button btLimpar = (Button) findViewById(R.id.btLimpar);
		
		btSomar.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				num1 = Double.parseDouble(ediNum1.getText().toString());
				num2 = Double.parseDouble(ediNum2.getText().toString());

				res = num1 + num2;

				resultado.setText(String.valueOf(res));
				
			}
		});

		btSubtrair.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {

				num1 = Double.parseDouble(ediNum1.getText().toString());
				num2 = Double.parseDouble(ediNum2.getText().toString());

				res = num1 - num2;

				resultado.setText(String.valueOf(res));
				
			}
		});

		btDividir.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {

				num1 = Double.parseDouble(ediNum1.getText().toString());
				num2 = Double.parseDouble(ediNum2.getText().toString());

				res = num1 / num2;

				resultado.setText(String.valueOf(res));
				
			}
		});

		btMultiplicar.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				num1 = Double.parseDouble(ediNum1.getText().toString());
				num2 = Double.parseDouble(ediNum2.getText().toString());

				res = num1 * num2;

				resultado.setText(String.valueOf(res));
				

			}
		});
		
		btLimpar.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				ediNum1.setText("");
				ediNum2.setText("");
				resultado.setText("");
				ediNum1.requestFocus();
				}
		});
		
		

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.calculadora, menu);
		return true;
	}

}
